package com.aiton.bamin.bamindaijiadrier.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.aiton.bamin.bamindaijiadrier.R;
import com.aiton.bamin.bamindaijiadrier.model.AppointedBill;

import java.util.List;

/**
     * 所有订单
     */
  public  class MyAppointedBillAdapter extends BaseAdapter {
    private  LayoutInflater inflater;
    private List<AppointedBill.DatasBean> mDatas;
        class ViewHolder {
            TextView textView_type;
            TextView textView_Time;
            TextView tv_bill_plus_title;
            TextView tv_bill_plus_money;
            TextView tv_bill_minus_title;
            TextView tv_bill_minus_money;
            View line_bill_plus;
            View line_bill_minus;

        }
    public MyAppointedBillAdapter(Context context, List<AppointedBill.DatasBean> mDatas){
        inflater = LayoutInflater.from(context);

        this.mDatas = mDatas;
    }
        @Override
        public int getCount() {
            return mDatas.size();
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;
            if (convertView == null) {
                holder = new ViewHolder();
                convertView = inflater.inflate(R.layout.item_bill, null);
                holder.textView_type = (TextView) convertView.findViewById(R.id.textView_type);
                holder.textView_Time = (TextView) convertView.findViewById(R.id.textView_Time);
                holder.tv_bill_plus_title = (TextView) convertView.findViewById(R.id.tv_bill_plus_title);
                holder.tv_bill_plus_money = (TextView) convertView.findViewById(R.id.tv_bill_plus_money);
                holder.tv_bill_minus_title = (TextView) convertView.findViewById(R.id.tv_bill_minus_title);
                holder.tv_bill_minus_money = (TextView) convertView.findViewById(R.id.tv_bill_minus_money);
                holder.line_bill_plus =  convertView.findViewById(R.id.line_bill_plus);
                holder.line_bill_minus = convertView.findViewById(R.id.line_bill_minus);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            AppointedBill.DatasBean resultsBean = mDatas.get(position);
            holder.textView_Time.setText("创建时间："+resultsBean.getTime());
            holder.textView_type.setText("类型："+resultsBean.getModel());
            if(TextUtils.equals(resultsBean.getModel(),"提现")){
                holder.line_bill_plus.setVisibility(View.GONE);
                holder.tv_bill_minus_title.setText("个人");
                Integer money = resultsBean.getMoney();
                CharSequence replace = TextUtils.replace(money + "", new String[]{"-"}, new String[]{""});
                holder.tv_bill_minus_money.setText(replace);
            }else if(TextUtils.equals(resultsBean.getModel(),"代驾")){
                holder.tv_bill_plus_money.setText(resultsBean.getDriverMoney()+"");
                holder.tv_bill_minus_money.setText(resultsBean.getSystemMoney()+"");
            }
            return convertView;
        }
    }
